******************************************************************
** title:	The (Non)-Religious Voter in Canadian Elections		**
** authors:	The Religious Voter									**
** data:	Canadian Election Studies 2019 and 2021									**
** date:	May 2024 - replication file      					**
******************************************************************

**Use the clean, pooled dataset - CES 2019 & 2021 combined
*To generate this clean and pooled dataset, please see the "pooling_catholic_ES.do" do file that cleans the raw CES 2019 and 2021
use "pooled_ces2019-21.dta"

*Scheme setting
set scheme plotplain

*Recode vote choice to remove the small parties
gen vote_choice2=vote_choice 
recode vote_choice2 (4/5=.) 
replace vote_choice2=4 if vote_choice2==6

label define VOTE 1 "LPC" 2 "CPC" 3 "NDP" 4 "Bloc"
label values vote_choice2 VOTE


***************************
***		 Figure 1       ***
***************************	

***
***In the ROC
***
eststo m3: mlogit vote_choice2 i.religion_cat_bcatho ///
		   woman i.age_cat post_sec income imm ///
		   mother_tongue i.rural_urban attendance_linear /// 
		   if prov_qc==0

margins, dydx(i.religion_cat_bcatho)

mplotoffset, title("Rest of Canada", box bexpand) recastci(rspike) ///
			 xtitle("Average marginal effect compared to catholic", size(small))  ///
			 xlabel(2 "Protestant" 3 "No religion" 4 `""Other" "religion""') ylabel(-.2(.05).15) ///
			 ytitle("Average marginal effect on vote choice", size(small)) ysc(titlegap(-8)) ///
			 legend(position(6) rows(1) order(4 "LPC" 5 "CPC" 6 "NDP" )) ///
			 plotopts(connect(none)) yline(0) 
				
graph save "roc_religion_mlogit_attendance_noweight.gph", replace 



***
***In Quebec
***
eststo m4: mlogit vote_choice2 i.religion_cat_bcatho ///
			woman i.age_cat post_sec income imm ///
			mother_tongue i.rural_urban attendance_linear if prov_qc==1

margins, dydx(religion_cat_bcatho)

mplotoffset, title("Quebec", box bexpand) recastci(rspike) ///
			 xtitle("Average marginal effect compared to catholic", size(small))  ///
			 xlabel(2 "Protestant" 3 "No religion" 4 `""Other" "religion""') ylabel(-.2(.05).15) ///
			 ytitle("", size(small)) ysc(titlegap(-8)) ///
			 legend(position(6) rows(1) ///
			 order(5 "LPC" 6 "CPC" 7 "NDP" 8 "Bloc" )) ///
			 plotopts(connect(none)) yline(0) 
				
graph save "qc_religion_mlogit_attendance_noweight.gph", replace
		
		
grc1leg roc_religion_mlogit_attendance_noweight.gph qc_religion_mlogit_attendance_noweight.gph, /// 
		legendfrom (qc_religion_mlogit_attendance_noweight.gph)

		


***************************
***		 Figure 2       ***
***************************	

***
***In the ROC
***

mlogit vote_choice2 i.religion_cat_bcatho ///
		   woman i.age_cat post_sec income imm ///
		   mother_tongue i.rural_urban attendance_linear /// 
		   if prov_qc==0

margins, dydx(attendance_linear)

mplotoffset, title("Rest of Canada", box bexpand) recastci(rspike) ///
			 xtitle("") ylabel(-.15(.05).15) ysc(titlegap(-8)) ///
			 xlabel(1 "LPC" 2 "CPC" 3 "NDP") ///
			 ytitle("Average marginal effect on vote choice", size(small)) ///
			 plotopts(connect(none)) yline(0) 
				
graph save "roc_attendance.gph", replace 

							
***
***In Quebec
***

mlogit vote_choice2 i.religion_cat_bcatho ///
			woman i.age_cat post_sec income imm ///
			mother_tongue i.rural_urban attendance_linear if prov_qc==1

margins, dydx(attendance_linear)

mplotoffset, title("Quebec", box bexpand) recastci(rspike) ///
			 xtitle("") ylabel(-.15(.05).15) ///
			 xlabel(1 "LPC" 2 "CPC" 3 "NDP" 4 "Bloc") ///
			 ytitle("", size(small))  ///
			 plotopts(connect(none)) yline(0) 
				
graph save "qc_attendance.gph", replace
				
				
graph combine roc_attendance.gph qc_attendance.gph	
	


***************************
***		 Figure 3       ***
***************************	

***
***LPC - ROC
***		
eststo m5: mlogit vote_choice2 i.religion_cat_bcatho##c.attendance_linear ///
		   woman i.age_cat post_sec income imm ///
		   mother_tongue i.rural_urban if prov_qc==0
margins, dydx(i.religion_cat_bcatho) at(attendance_linear=(0 0.2 0.4 0.6 0.8 1)) predict(outcome(1))
mplotoffset, title("LPC", box bexpand) recastci(rspike) ///
			 xtitle("") ///
			 xlabel(-0.1 " " 0 "Never" 0.2 `" "Once" "a year" "' 0.4 `" "2 to 11" "times a year" "'  /// 
			 0.6 `" "Once" "a month" "'  0.8 `" "2 to 3" "times a month" "' 1 `" "Once a week" "or more" "' 1.1 " ", labsize(vsmall)) ///
			 ytitle("Average marginal effect", size(vsmall)) ysc(titlegap(-8)) ///
			 ylabel(-0.2(0.1)0.2) ///
			 legend(position(6) rows(1) ///
			 order(4 "Protestant" 5 "No religion" 6 "Other religion") size(vsmall)) ///
			 plotopts(connect(none)) yline(0) 
				
graph save "roc_LPC_moderation_attendance.gph", replace
 

***
***CPC - ROC
***		
esttab m5
margins, dydx(i.religion_cat_bcatho) at(attendance_linear=(0 0.2 0.4 0.6 0.8 1)) predict(outcome(2))
mplotoffset, title("CPC", box bexpand) recastci(rspike) ///
			 xtitle("") ///
			 xlabel(-0.1 " " 0 "Never" 0.2 `" "Once" "a year" "' 0.4 `" "2 to 11" "times a year" "'  /// 
			 0.6 `" "Once" "a month" "'  0.8 `" "2 to 3" "times a month" "' 1 `" "Once a week" "or more" "' 1.1 " ", labsize(vsmall)) ///
			 ytitle("", size(vsmall)) ysc(titlegap(-8)) ///
			 ylabel(-0.2(0.05)0.2) ///
			 legend(position(6) rows(1) ///
			 order(4 "Protestant" 5 "No religion" 6 "Other religion" )) ///
			 plotopts(connect(none)) yline(0) 
				
graph save "roc_CPC_moderation_attendance.gph", replace 	

***
***NDP - ROC
***		
esttab m5
margins, dydx(i.religion_cat_bcatho) at(attendance_linear=(0 0.2 0.4 0.6 0.8 1)) predict(outcome(3))
mplotoffset, title("NDP", box bexpand) recastci(rspike) ///
			 xtitle("") ///
			 xlabel(-0.1 " " 0 "Never" 0.2 `" "Once" "a year" "' 0.4 `" "2 to 11" "times a year" "'  /// 
			 0.6 `" "Once" "a month" "'  0.8 `" "2 to 3" "times a month" "' 1 `" "Once a week" "or more" "' 1.1 " ", labsize(vsmall)) ///
			 ytitle("Average marginal effect", size(vsmall)) ysc(titlegap(-8)) ///
			 ylabel(-0.2(0.05)0.2) ///
			 legend(position(6) rows(1) ///
			 order(4 "Protestant" 5 "No religion" 6 "Other religion" )) ///
			 plotopts(connect(none)) yline(0) 
				
graph save "roc_NDP_moderation_attendance.gph", replace


*Graph combine (ROC)
grc1leg roc_LPC_moderation_attendance.gph roc_CPC_moderation_attendance.gph ///
		roc_NDP_moderation_attendance.gph, ycommon title("Rest of Canada", box bexpand) ///
		legendfrom (roc_LPC_moderation_attendance.gph) imargin(vsmall)
graph save "moderation_roc_attendance", replace		


***
***LPC - QC
***	
eststo m6: mlogit vote_choice2 i.religion_cat_bcatho##c.attendance_linear ///
		   woman i.age_cat post_sec income imm ///
		   mother_tongue i.rural_urban if prov_qc==1
margins, dydx(i.religion_cat_bcatho) at(attendance_linear=(0 0.2 0.4 0.6 0.8 1)) predict(outcome(1))
mplotoffset, title("LPC", box bexpand) recastci(rspike) ///
			 xtitle("") ///
			 xlabel(-0.1 " " 0 "Never" 0.2 `" "Once" "a year" "' 0.4 `" "2 to 11" "times a year" "'  /// 
			 0.6 `" "Once" "a month" "'  0.8 `" "2 to 3" "times a month" "' 1 `" "Once a week" "or more" "' 1.1 " ", labsize(vsmall)) ///
			 ytitle("Average marginal effect", size(vsmall)) ysc(titlegap(-8)) ///
			 ylabel(-0.4(0.1)0.4) ///
			 legend(position(6) rows(1) ///
			 order(4 "Protestant" 5 "No religion" 6 "Other religion") size(vsmall)) ///
			 plotopts(connect(none)) yline(0) 
				
graph save "qc_LPC_moderation_attendance.gph", replace 


***
***CPC - QC
***	
esttab m6
margins, dydx(i.religion_cat_bcatho) at(attendance_linear=(0 0.2 0.4 0.6 0.8 1)) predict(outcome(2))
mplotoffset, title("CPC", box bexpand) recastci(rspike) ///
			 xtitle("") ///
			 xlabel(-0.1 " " 0 "Never" 0.2 `" "Once" "a year" "' 0.4 `" "2 to 11" "times a year" "'  /// 
			 0.6 `" "Once" "a month" "'  0.8 `" "2 to 3" "times a month" "' 1 `" "Once a week" "or more" "' 1.1 " ", labsize(vsmall)) ///
			 ytitle("", size(vsmall)) ysc(titlegap(-8)) ///
			 ylabel(-0.4(0.1)0.4) ///
			 legend(position(6) rows(1) ///
			 order(4 "Protestant" 5 "No religion" 6 "Other religion")) ///
			 plotopts(connect(none)) yline(0) 
				
graph save "qc_CPC_moderation_attendance.gph", replace 


***
***NDP - QC
***	
esttab m6
margins, dydx(i.religion_cat_bcatho) at(attendance_linear=(0 0.2 0.4 0.6 0.8 1)) predict(outcome(3))
mplotoffset, title("NDP", box bexpand) recastci(rspike) ///
				xtitle("Religiosity", size(small)) ///
				xlabel(-0.1 " " 0 "Never" 0.2 `" "Once" "a year" "' 0.4 `" "2 to 11" "times a year" "'  /// 
			    0.6 `" "Once" "a month" "'  0.8 `" "2 to 3" "times a month" "' 1 `" "Once a week" "or more" "' 1.1 " ", labsize(vsmall)) ///
				ytitle("Average marginal effect", size(vsmall)) ysc(titlegap(-8)) ///
				ylabel(-0.4(0.1)0.4) ///
				legend(position(6) rows(1) ///
				order(4 "Protestant" 5 "No religion" 6 "Other religion")) ///
				plotopts(connect(none)) yline(0) 
				
graph save "qc_NDP_moderation_attendance", replace 


***
***BLOC - QC
***	
esttab m6
margins, dydx(i.religion_cat_bcatho) at(attendance_linear=(0 0.2 0.4 0.6 0.8 1)) predict(outcome(4))
mplotoffset, title("Bloc", box bexpand) recastci(rspike) ///
			 xtitle("Religiosity", size(small)) ///
			 xlabel(-0.1 " " 0 "Never" 0.2 `" "Once" "a year" "' 0.4 `" "2 to 11" "times a year" "'  /// 
			 0.6 `" "Once" "a month" "'  0.8 `" "2 to 3" "times a month" "' 1 `" "Once a week" "or more" "' 1.1 " ", labsize(vsmall)) ///
			 ytitle("", size(vsmall)) ysc(titlegap(-8)) ///
			 ylabel(-0.4(0.1)0.4) ///
			 legend(position(6) rows(1) ///
			 order(4 "Protestant" 5 "No religion" 6 "Other religion")) ///
			 plotopts(connect(none)) yline(0) 
				
graph save "qc_Bloc_moderation_attendance.gph", replace 


*Graph combine (Qc)
grc1leg qc_LPC_moderation_attendance.gph qc_CPC_moderation_attendance.gph ///
		qc_NDP_moderation_attendance.gph qc_Bloc_moderation_attendance.gph, ///
		title("Quebec", box bexpand) legendfrom (qc_LPC_moderation_attendance.gph) imargin(vsmall)
graph save "moderation_qc_attendance", replace


*Graph combine (Qc+ROC)	
grc1leg2 moderation_roc_attendance.gph moderation_qc_attendance.gph, legendfrom(moderation_roc_attendance.gph) row(2) ysize(14.5) xsize(12.5) ///
	graphregion(margin(tiny)) imargin(vsmall)		
	
	
*Regression output
esttab m5 ///
	using "tableA6_final.rtf", ///
	label nogap  compress unstack ///
	pr2  b(3) se(3) nonumbers replace noomitted nobase
	
esttab m6 ///
	using "tableA7_finale.rtf", ///
	label nogap  compress unstack ///
	pr2  b(3) se(3) nonumbers replace noomitted nobase		
	
	
	
	
	
	
	


***************************
***		  Online        ***
***************************	
***************************
***		 Appendix       ***
***************************	

***************************
***		 Table A1       ***
***************************	
*To keep the subsample used in the analyses
mlogit vote_choice2 i.religion_cat_bcatho ///
		   woman i.age_cat post_sec income imm ///
		   mother_tongue i.rural_urban
		   
tab vote_choice_brute if elecid==2019
tab vote_choice_brute if elecid==2021 



***************************
***		 Table A2       ***
***************************	


eststo a2: mlogit vote_choice2 i.religion_cat_bcatho ///
		   woman i.age_cat post_sec income imm ///
		   mother_tongue i.rural_urban attendance_linear /// 
		   if prov_qc==0
		  

esttab a2 ///
			using "TableA2.rtf", ///
			label nogap  compress unstack ///
			pr2  b(3) se(3)  nonumbers replace  noomitted nobase 
			

				
***************************
***		 Table A3       ***
***************************


eststo a3: mlogit vote_choice2 i.religion_cat_bcatho ///
			woman i.age_cat post_sec income imm ///
			mother_tongue i.rural_urban attendance_linear if prov_qc==1

esttab a3 ///
			using "TableA3.rtf", ///
			label nogap  compress unstack ///
			pr2  b(3) se(3)  nonumbers replace  noomitted nobase 	
				
				
	
